<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page import="top.lbqaq.pojo.Product" %>
<%@ page import="java.util.List" %>
<%@ page import="top.lbqaq.util.pageBean" %><%--
  Created by IntelliJ IDEA.
  User: the world
  Date: 2021/11/28
  Time: 21:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/jsp/common/head.jsp" %>


<%String msg= (String) request.getAttribute("msg");
if(msg!=null){%>
<script >
    alert("<%=msg%>");
</script>
   <%}         %>
    <div class="card-body">
            <div class="row">
            <div class="col-10">
                <form action="${pageContext.request.contextPath}/product">
                    <div class="col-md-8">
                        <label>查询条件</label>
                        <select class="form-control form-control-sm mb-3" name="method">
                            <option value="selectBy" style="display:none">请选择查询方式</option>
                            <option value="selectByCategory1">按类别1查询</option>
                            <option value="selectByCategory2">按类别2查询</option>
                            <option value="selectByName">按名称查询</option>
                            <option value="selectAll">查询全部</option>
                        </select>

                    <div class="row">

                    <div class="col-md-4">
                        <input type="text" class="form-control" value="填写条件" name="name"/>
                    </div>
                    <div class="col-md-2">
                    <input type="submit" class="btn btn-primary" value="确定"/>
                    </div>
                    </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <form action="${pageContext.request.contextPath}/product">
    <table class="table table-hover">
        <thead>

        <tr>
            <th scope="col">id</th>
            <th scope="col">类别1</th>
            <th scope="col">类别2</th>
            <th scope="col">编号</th>
            <th scope="col">产品名称</th>
            <th scope="col">单位</th>
            <th scope="col">图片</th>
            <th scope="col">备注</th>
            <th scope="col">删除</th>
            <th scope="col">
            <div class="col-md-2">
                <input type="submit" class="btn btn-primary" name="delete" value="确定删除"/>
            </div>
            </th>
            <th scope="col">
                <div class="col-md-2">
                    <input type="submit" class="btn btn-primary" name="insert" value="增加"/>
<%--                    <a href="${pageContext.request.contextPath}/jsp/px.jsp">点此跳转</a>--%>
                </div>
            </th>
        </tr>

        </thead>


  <tbody>
    <% if(request.getAttribute("productList")!=null){
         pageBean<Product> products = (pageBean<Product>) request.getAttribute("productList");
         for (int i = 0; i < products.getList().size(); i++) {
    %>
    <tr>
        <th>
            <%= products.getList().get(i).getId()%>
        </th>
        <th>
            <%= products.getList().get(i).getProductCategory1()%>
        </th>
        <th>
            <%= products.getList().get(i).getProductCategory2()%>
        </th>
        <th>
            <%= products.getList().get(i).getProductNo()%>

        </th>
        <th>
            <%= products.getList().get(i).getProductName()%>
        </th>
        <th>
            <%= products.getList().get(i).getProductUnit()%>
        </th>
        <th>
            <%= products.getList().get(i).getProductPicture()%>
        </th>
        <th>
            <%= products.getList().get(i).getProductRemark()%>
        </th>
        <th>
            <label>
                <input type="checkbox" name="check" value="<%=products.getList().get(i).getProductNo()%>"/>
            </label>
        </th>
        <th>
            <a style="margin-top:5px;" class="btn btn-primary btn-sm" href="${pageContext.request.contextPath}/product?type=xiu&id=<%=products.getList().get(i).getId()%>"name="update">修改</a>
        </th>

        <%
        }
    %>
        <%

        }
    %>

    </form>
</table>

<c:if test="${productList.pageNum !=null}">
<a href="${pageContext.request.contextPath}/product?pageNum=1&method1=${method1}">首页</a>
<%--如果当前页为第一页时，就没有上一页这个超链接显示 --%>
<c:if test="${productList.pageNum ==1}">
    <c:forEach begin="${productList.start}" end="${productList.end}" step="1" var="i">
        <c:if test="${productList.pageNum == i}">
            ${i}
        </c:if>
        <c:if test="${productList.pageNum != i}">
            <a href="${pageContext.request.contextPath}/product?pageNum=${i}&method1=${method1}">${i}</a>
        </c:if>
    </c:forEach>
    <c:if test="${productList.totalPage !=1}">
        <a href="${pageContext.request.contextPath}/product?pageNum=${productList.pageNum+1}&method1=${method1}">下一页</a>
    </c:if>
</c:if>
<%--如果当前页不是第一页也不是最后一页，则有上一页和下一页这个超链接显示 --%>
<c:if test="${productList.pageNum > 1 && productList.pageNum < productList.totalPage}">
    <a href="${pageContext.request.contextPath}/product?pageNum=${productList.pageNum-1}&method1=${method1}">上一页</a>
    <c:forEach begin="${productList.start}" end="${productList.end}" step="1" var="i">
        <c:if test="${productList.pageNum == i}">
            ${i}
        </c:if>
        <c:if test="${productList.pageNum != i}">
            <a href="${pageContext.request.contextPath}/product?pageNum=${i}&method1=${method1}">${i}</a>
        </c:if>
    </c:forEach>
    <a href="${pageContext.request.contextPath}/product?pageNum=${productList.pageNum+1}&method1=${method1}">下一页</a>
</c:if>

<%--&lt;%&ndash; 如果当前页是最后一页，则只有上一页这个超链接显示，下一页没有 &ndash;%&gt;如果是第一页不需要--%>
<c:if test="${productList.pageNum == productList.totalPage}">
    <c:if test="${productList.pageNum !=1&&productList.pageNum !=null}">
        <a href="${pageContext.request.contextPath}/product?pageNum=${productList.pageNum-1}&method1=${method1}">上一页</a>
        <c:forEach begin="${productList.start}" end="${productList.end}" step="1" var="i">
            <c:if test="${productList.pageNum == i}">
                ${i}
            </c:if>
            <c:if test="${productList.pageNum != i}">
                <a href="${pageContext.request.contextPath}/product?pageNum=${i}&method1=${method1}">${i}</a>
            </c:if>
        </c:forEach>
    </c:if>
</c:if>
<%--尾页 --%>
<a href="${pageContext.request.contextPath}/product?pageNum=${productList.totalPage}&method1=${method1}">尾页</a>
</c:if>

<%@include file="/jsp/common/footer.jsp"%>